package com.agileboot.domain.feedback.db;


import cn.hutool.core.lang.Assert;
import com.agileboot.domain.feedback.dto.UserFeedbackReq;
import com.agileboot.domain.system.user.db.SysUserEntity;
import com.agileboot.domain.system.user.db.SysUserService;
import com.agileboot.infrastructure.user.AuthenticationUtils;
import com.agileboot.infrastructure.user.web.SystemLoginUser;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestBody;

import java.util.Objects;

/**
 *
 */
@Service
public class UserFeedbackServiceImpl extends ServiceImpl<UserFeedbackMapper, UserFeedback> implements IUserFeedbackService {

    @Autowired
    private SysUserService userService;
//    @Autowired
//    private IUserFeedbackService userFeedbackService;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addFeedback(@RequestBody UserFeedbackReq userFeedbackReq) {
        //校验参数
        SystemLoginUser user = AuthenticationUtils.getSystemLoginUser();
        Assert.isTrue(Objects.nonNull(user),"用户不存在");
        userFeedbackReq.setUserId(user.getUserId());
        //准备参数，填充参数
        userFeedbackReq.setStatus(0);
        userFeedbackReq.setUserName(user.getUsername());
        //转换成db实体类
        UserFeedback userFeedback = userFeedbackReq.toEntity();
        baseMapper.insert(userFeedback);
    }
}
